package com.app.megaprosoft.DB;

import java.sql.*;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ItemSize {
	 
	 ResultSet rs = null;
	 SQLiteDBClass myDb;
	 SQLiteDatabase db;
	 Context context;
	 private static final String TABLE_ItemSize = "_ItemSize";
	 public Context getContext() {
		return context;
	 }

	 public void setContext(Context context) {
		this.context = context;
	 }
	private String OID,
		    UsrOpt,
		    IsActive,
		    IsDeleted,
			ItemSizeCode,
			ItemSizeName,
			ContainSize,
			ItemGroup;
	   		// private float ContainSize;
		
	public ItemSize() {ItemSizeCode=ItemSizeName=ContainSize=ItemGroup="";
			//ContainSize = 0.0F;
	}  

	
	public ItemSize(
			String OID,
    		String UsrOpt,
    		String IsActive,
    		String IsDeleted,
    		String ItemSizeCode,
    		String ItemSizeName,
    		String ContainSize,
    		String ItemGroup
    )
    {
		this.OID = OID;
    	this.UsrOpt = UsrOpt;
    	this.IsActive = IsActive;
    	this.IsDeleted = IsDeleted;
    	this.ItemSizeCode = ItemSizeCode;
    	this.ItemSizeName = ItemSizeName;
    	this.ContainSize = ContainSize;
    	this.ItemGroup = ItemGroup;
    }
	
	public String getOID() {
		return OID;
	}

	public void setOID(String oID) {
		OID = oID;
	}

	public String getUsrOpt() {
		return UsrOpt;
	}

	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}

	public String getIsActive() {
		return IsActive;
	}

	public void setIsActive(String isActive) {
		IsActive = isActive;
	}

	public String getIsDeleted() {
		return IsDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}
	
	public void setItemSizeCode(String ItemSizeCode)
	{
		this.ItemSizeCode = ItemSizeCode;
	}
	public void setItemSizeName(String ItemSizeName)
	{
		this.ItemSizeName = ItemSizeName;
	}
	public void setContainSize(String ContainSize)
	{
		//this.ContainSize = Float.valueOf(ContainSize).floatValue();
		this.ContainSize = ContainSize;
	}	
	public void setItemGroup(String ItemGroup)
	{
		this.ItemGroup = ItemGroup;
	}
	//--------------------------------------------------------------
	public String getItemGroup()
	{
		return this.ItemGroup;
	}	
	public String getItemSizeCode()
	{
		return this.ItemSizeCode;
	}
	public String getItemSizeName()
	{
		return this.ItemSizeName;
	}
	public String getContainSize()
	{
	    return this.ContainSize;
	}
	
	public ResultSet selectItemSize(String StrItemSizeName) throws Exception {
		Connect con = new Connect(); 
		String StrSql   = "SELECT [OID]," +
				"[LastModified]," +
				"[ModifyDate]," +
				"[ModifyTime]," +
				"[ModifiedBy]," +
				"[UserModify]," +
				"[CreatedDate]," +
				"[CreateDate]," +
				"[CreateTime]," +
				"[CreatedBy]," +
				"[UserCreate]," +
				"[IsActive]," +
				"[IsDeleted]," +
				
				"[ItemSizeCode],"+
                "[ItemSizeName],"+		
                "[ContainSize],"+	
                "[ItemGroupCode],"+
                "[ItemGroupDesc] "+	
                
                "FROM [dbo].[udfItemSize]() "+
				"WHERE [IsDeleted]='0' ";   
			     	
		if (!StrItemSizeName.equals("")) {
            StrSql += "AND [ItemSizeName] LIKE '%" + StrItemSizeName + "%'";
        }
    	
		return con.selectData(StrSql);
	 }
	
	public ResultSet defineItemSize() throws Exception {
		Connect con = new Connect(); 
        String StrSql = "SELECT [OID]," +
        		"[ItemSizeCode]"+
				",[ItemSizeName] "+		
               
                "FROM [dbo].[udfItemSize] ()";

        StrSql += "ORDER BY [ItemSizeName] ASC";

        return con.selectData(StrSql);
    }
//	
//	 public void closeConnecttion() throws Exception {
//    	 if (conn != null) {
//             conn.close();
//         }
//    }
	 
	 public void DEFINE_ItemSize() {
			rs = null;
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			try {
				rs = selectItemSize("");
				while (rs.next()) {
					ContentValues Val = new ContentValues();
					Val.put("ItemSizeOID", rs.getString("OID"));

					Val.put("ItemSizeCode", rs.getString("ItemSizeCode"));
					Val.put("ItemSizeName", rs.getString("ItemSizeName"));
					Val.put("ContainSize", rs.getString("ContainSize"));
					Val.put("ItemGroupCode", rs.getString("ItemGroupCode"));
					Val.put("ItemGroupDesc", rs.getString("ItemGroupDesc"));

					db.insert(TABLE_ItemSize, null, Val);
				}
				rs.close();
			} catch (Exception e) {
				Log.d("TABLE_ItemSize", "Create Table not Successfully.");
			}
			Log.d("TABLE_ItemSize", "Create Table Successfully.");
			db.close();
		}
    
}
